package com.jack.controller;


import com.jack.pojo.Emp;
import com.jack.queryParam.EmpQueryParam;
import com.jack.result.PageResult;
import com.jack.result.Result;
import com.jack.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 员工管理控制类
 */
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpService empService;


    /**
     * 新增员工
     * @param emp
     * @return
     */
    @PostMapping
    public Result addEmp(@RequestBody Emp emp) {
        empService.addEmp(emp);
        return Result.success();
    }

    /**
     * 批量删除员工
     * @return
     */
    @DeleteMapping
    public Result deleteEmps (@RequestParam List<Integer> ids){
        empService.deleteEmps(ids);
        return Result.success();
    }

    /**
     * 更改员工信息
     * @param emp
     * @return
     */
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        empService.updateEmp(emp);
        return Result.success();
    }

    /**
     * 查询员工列表
     * @return
     */
    @GetMapping("/list")
    public Result getEmpList(){
        List<Emp> emps = empService.getEmpList();
        return Result.success(emps);
    }

    /**
     * 条件分页查询
     * @return
     */
    @GetMapping
    public Result pageEmps ( EmpQueryParam empQueryParam) {
        PageResult<Emp> pageEmps = empService.pageEmps(empQueryParam);
        return Result.success(pageEmps);
    }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getEmpById(@PathVariable Long id){
        Emp emp = empService.getEmpById(id);
        return Result.success(emp);
    }
}
